﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Business;

namespace University.Workshop.Presenters.Expenses.Modify
{
    public class  PresenterModifyExpense
    {
        IModifyExpenseView view;
        Model.Expense expenseToModify = new Model.Expense();

        public PresenterModifyExpense(IModifyExpenseView view, Model.Expense ex)
        {
            this.view = view;
            this.expenseToModify = ex;
            //this.expenseToRegister.UserId = ex.UserId;
        }

        public void UpdateViewData()
        {
            view.Amount = expenseToModify.Amount;
            view.Description = expenseToModify.Description;
            view.Item = expenseToModify.ExpenseType;
            view.Price = expenseToModify.Price;
            view.Receipt = expenseToModify.Receipt;
            view.SpendDate = expenseToModify.SpendDate;
        }

        public bool UpdateExpense()
        {
            try
            {
                Model.Expense e = new Model.Expense() { DateRegistry=expenseToModify.DateRegistry, UserId = expenseToModify.UserId, SpendDate = view.SpendDate, Price=view.Price, ExpenseType=view.Item, Amount=view.Amount, Description=view.Description, Receipt=view.Receipt};
                ManagerExpense.VerifyDataExpense(e);
                ManagerExpense.UpdateExpense(e);
                return true;
            }
            catch (Exception ex)
            {
                view.ErrorMessage(string.Format(ex.Message, "Modificar Gasto"));
                return false;
            }



        }
    }
}
